Structures: Initialisation
Pascal C/C++
wNO STANDARD PASCAL EQUIVALENT (BUT MANY DIALECTS ALLOW THIS)
wA C variable may be initialised when it is declared – e.g.
wint i = 3;
wchar c = ‘A’;
wfloat a[3] = {1.0, 2.0, 3.0};
wstruct
w{ char name[11];
w   float gpa;
w} student = {“Smith”, 4.0};
NOTE: In C++, initialisation of a struct this way is not allowed if any field is of class type, requiring a constructor.
In C++, initialisation of a struct this way is not allowed if any field is of class type, requiring a constructor. Thus, in particular, this example would not work correctly if name were declared as string, since string is a library class.